Skip to content

fix: HelmetDataContext.helmet type lie — allow null, remove non-null assertion#261

Merged
staylor merged 3 commits intov3.0.0from
copilot/sub-pr-260
Mar 3, 2026
Merged

fix: HelmetDataContext.helmet type lie — allow null, remove non-null assertion#261
staylor merged 3 commits intov3.0.0from
copilot/sub-pr-260

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

HelmetDataContext.helmet was typed as HelmetServerState (non-nullable) while setHelmet accepted HelmetServerState | null and used a non-null assertion (serverState!) to paper over the mismatch — leaving context.helmet silently null at runtime despite the type claiming otherwise.

Changes

  • src/HelmetData.ts: Widen HelmetDataContext.helmet to HelmetServerState | null; remove the ! assertion in setHelmet
  • src/Provider.tsx: Update public context.helmet prop type to HelmetServerState | null to match
// Before
interface HelmetDataContext {
  helmet: HelmetServerState; // ← lie: can actually be null at runtime
}
setHelmet: (serverState: HelmetServerState | null) => {
  this.context.helmet = serverState!; // ← suppresses the type error
}

// After
interface HelmetDataContext {
  helmet: HelmetServerState | null; // ← honest
}
setHelmet: (serverState: HelmetServerState | null) => {
  this.context.helmet = serverState; // ← no assertion needed
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 3, 2026 11:43
…tion

Co-authored-by: staylor <52932+staylor@users.noreply.github.com>
Co-authored-by: staylor <52932+staylor@users.noreply.github.com>
Copilot AI changed the title [WIP] Update React 19 support and perform TypeScript cleanup fix: HelmetDataContext.helmet type lie — allow null, remove non-null assertion Mar 3, 2026
@staylor staylor marked this pull request as ready for review March 3, 2026 11:50
@staylor staylor merged commit 60d2ebd into v3.0.0 Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants